package com.SouthernWall_404.age_tool.common.Network.Packets.S2C;

import com.SouthernWall_404.age_tool.common.Network.Packets.S2C.ClientHandler.MimicBlockRespondPacketHandler;
import com.SouthernWall_404.age_tool.common.Network.Packets.S2C.ClientHandler.MusicBlockNBTClientHandler;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;

import java.util.function.Supplier;

public class MimicBlockRespondS2CPacket {

    public CompoundTag blockPack;
    public BlockPos blockPos;


    public MimicBlockRespondS2CPacket(CompoundTag modPack, BlockPos blockPos)
    {
        this.blockPos=blockPos;
        this.blockPack=modPack;
    }

    public MimicBlockRespondS2CPacket(FriendlyByteBuf buf) {
        this.blockPos=buf.readBlockPos();
        this.blockPack=buf.readNbt();
    }

    public void encode(FriendlyByteBuf buf) {
        buf.writeBlockPos(this.blockPos);
        buf.writeNbt(this.blockPack);
    }
    public void handle(Supplier<NetworkEvent.Context> ctx)
    {
        ctx.get().enqueueWork(() ->
                // 确保其仅在物理客户端上执行
                DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> MimicBlockRespondPacketHandler.hanlder(this,ctx))
        );
        ctx.get().setPacketHandled(true);
    }
}
